<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro"%>
<style>
<!--
.h10{
	height: 10px;
}
.form-group{
	margin-top:10px;
}
#search{
	margin-top:10px;
}
.form-control.area{
	width:20%;
}
-->
</style>
	<div class="m-b-md">
		<div class="h10"></div>
		<form class="form-inline" role="form" id="searchForm" name="searchForm">
			<div class="form-group">
				<label class="control-label">
				<span>活动主题:</span></label>
				<input class="form-control" id="orgName" qt="like" name="partyFormMap.subject">
			</div>
			<div class="form-group" style="width:18em;">
				<label class="control-label">
				<span>开始时间:</span></label>
				<input class="form-control" id="beginTime" qt="like" name="partyFormMap.startTime">
			</div>
			<div class="form-group" style="width:18em;">
				<label class="control-label">
				<span>结束时间:</span></label>
				<input class="form-control" id="endTime" qt="like" name="partyFormMap.endTime">
			</div>
			<div class="form-group">
				<label class="control-label">
				<span>状态:</span></label>
				<select class="form-control" name="partyFormMap.status">
					<option value="">全部</option>
					<c:forEach items="${dict }" var="record">
					<option value="${record.value }">${record.label }</option>
					</c:forEach>
				</select>
			</div>
			<shiro:hasRole name="admin">
			<br/>
				<div class="form-group">
					<label class="control-label">
					<span>所属地区:</span></label>
					<select class="form-control area" id="province" name="partyFormMap.province" ></select>
					<select class="form-control area" id="city" name="partyFormMap.city"></select>
					<select class="form-control area" id="area" name="partyFormMap.area"></select>
					<select class="form-control area" id="street" name="partyFormMap.street"></select>
				</div>
			</shiro:hasRole>
			<a href="javascript:void(0)" class="btn btn-default" id="search">查询</a>
			<a href="javascript:grid.exportData('/party/exportParty.shtml')" class="btn btn-info" id="search">导出excel</a>
			<shiro:hasAnyRoles name="admin,branch,street">
			<button type="button" id="delFun" class="btn btn-danger marR10" style="margin-top:10px;">删除</button>
			<button type="button" id="success" class="btn btn-success marR10" style="margin-top:10px;">推荐</button>
			<button type="button" id="primary" class="btn btn-primary marR10" style="margin-top:10px;">取消推荐</button>
			</shiro:hasAnyRoles>
		</form>
	</div>
	<header class="panel-heading">
	<div class="doc-buttons">
		<c:forEach items="${res}" var="key">
			${key.description}
		</c:forEach>
	</div>
	</header>
	<div class="table-responsive">
		<div id="paging" class="pagclass"></div>
	</div>
<script type="text/javascript">
	initRegionFormControl("310000","310100","310112","",true);//初始化省市区联动
</script>
<script type="text/javascript">

var dict = [];
<c:forEach items="${dict }" var="record">
dict.push({'value':'${record.value}','label':'${record.label}'});
</c:forEach>


var partyType = [];
<c:forEach items="${partyType }" var="record">
partyType.push({'value':'${record.value}','label':'${record.label}'});
</c:forEach>

jeDate.skin("gray")  //调用不同风格的样式  分别有 默认("jedate")、红色("red")、绿色("green")、灰色("gray")、
jeDate({
	dateCell:"#beginTime",  //目标元素。由于jedate.js封装了一个轻量级的选择器，因此dateCell还允许你传入class、tag这种方式 '#id .class'
	format:"YYYY-MM-DD",
	isinitVal:false, //显示时间
	isTime:true, 
    festival: true, //显示节日
	minDate:"1990-01-01",
	choosefun:function(){
		addDetail();
	}
});
jeDate({
	dateCell:"#endTime",  //目标元素。由于jedate.js封装了一个轻量级的选择器，因此dateCell还允许你传入class、tag这种方式 '#id .class'
	format:"YYYY-MM-DD",
	isinitVal:false, //显示时间
	isTime:true, 
    festival: true, //显示节日
	minDate:"1990-01-01",
	choosefun:function(){
		addDetail();
	}
});
var pageii = null;
var grid = null;
$(function() {
	grid = lyGrid({
		pagId : 'paging',
		l_column : [{
			colkey : "id",
			name : "操作",
			width : "110px",
			renderData : function(rowindex,data, rowdata, column) {
				return "<img class='imgbtn' title='活动详情' src='" + rootPath + "/images/findDetail.png' onclick=\"viewFun('"+data+"')\"/>&nbsp;&nbsp;&nbsp;&nbsp;"+
				"<img class='imgbtn' title='活动明细' src='" + rootPath + "/images/view.png' onclick=\"viewDetail('"+data+"')\"/>";
			}
		},{
			colkey : "subject",
			name : "活动主题",
			renderData : function(rowindex,data, rowdata, column) {
				return "<span title='"+data+"'>"+data+"</span>";
			}
		},{
			colkey : "openid",
			name : "发起人",
			renderData : function(rowindex,data, rowdata, column) {
				return "<span title='"+data+"'>"+data+"</span>";
			}
		},{
			colkey : "orgInfoId",
			name : "所属机构",
			renderData : function(rowindex,data, rowdata, column) {
				return "<span title='"+data+"'>"+data+"</span>";
			}
		},{
			colkey : "contact",
			name : "联络人",
			renderData : function(rowindex,data, rowdata, column) {
				return "<span title='"+data+"'>"+data+"</span>";
			}
		},{
			colkey : "phone",
			name : "联络电话",
			renderData : function(rowindex,data, rowdata, column) {
				return "<span title='"+data+"'>"+data+"</span>";
			}
		},{
			colkey : "address",
			name : "地址",
			renderData : function(rowindex,data, rowdata, column) {
				return "<span title='"+data+"'>"+data+"</span>";
			}
		},{
			colkey : "qrCode",
			name : "二维码",
			renderData : function(rowindex,data, rowdata, column) {
				if(data){
					return "<a href='javaScript:;' onclick=\"xianzai('"+data+"')\">二维码下载</a>";					
				}else{
					return "无";
				}
			}
		}, {
			colkey : "type",
			name : "活动类型",
			renderData : function(rowindex,data, rowdata, column) {
				var val = "";
				$.each(partyType,function(i,e){
					if (e.value == data) {
						val = e.label;
						return false;
					}
				});
				return val;
			}
		},{
			colkey : "startTime",
			name : "开始时间",
			renderData : function(rowindex,data, rowdata, column) {
				return "<span title='"+new Date(data).format("yyyy-MM-dd hh:mm")+"'>"+new Date(data).format("yyyy-MM-dd hh:mm")+"</span>";
			}
		},{
			colkey : "endTime",
			name : "结束时间",
			renderData : function(rowindex,data, rowdata, column) {
				return "<span title='"+new Date(data).format("yyyy-MM-dd hh:mm")+"'>"+new Date(data).format("yyyy-MM-dd hh:mm")+"</span>";
			}
		}, {
			colkey : "status",
			name : "状态",
			renderData : function(rowindex,data, rowdata, column) {
				var val = "";
				$.each(dict,function(i,e){
					if (e.value == data) {
						val = e.label;
						return false;
					}
				});
				return val;
			}
		},{
			colkey : "isRecommend",
			name : "是否重点推荐",
			renderData : function(rowindex,data, rowdata, column) {
				if(data==1){
					return "<span title='重点推荐'>重点推荐</span>";	
				}else{
					return "<span title='未推荐'>未推荐</span>";
				}
			}
		}],
		jsonUrl : rootPath + '/party/findByPage.shtml',
		checkbox : true
	});
	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();// 初始化传参数
		$("input[qt=like]").each(function() {
			if ($(this).val().trim() != "") {
				searchParams[$(this).attr("name")] = "%" + $(this).val().trim() + "%";
			}
		});
		grid.setOptions({
			data : searchParams
		});
	});
	$("#passFun").click("click", function() {
		passFun();
	});
	$("#rejectFun").click("click", function() {
		rejectFun();
	});
	$("#viewFun").click("click", function() {
		viewFun();
	});
	$("#viewDetail").click("click",function(){
		viewDetail();
	});
	$("#delFun").click("click", function() {
		delFun();
	});
	$("#success").click("click",function(){
		recommend();
	});
	$("#primary").click("click",function(){
		unRecommend();
	});
});
function passFun(cbox) {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择机构！！");
		return;
	}
	layer.confirm('确认审核通过？', function(index) {
		var url = rootPath + '/org/pass.shtml';
		var s = CommnUtil.ajax(url, { ids : cbox.join(",") }, "json");
		if (s == "success") {
			layer.msg('操作成功');
			grid.loadData();
		} else {
			layer.msg('操作失败');
		}
	});
}

function rejectFun(cbox) {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择机构！！");
		return;
	}
	layer.confirm('确认审核拒绝？', function(index) {
		var url = rootPath + '/party/reject.shtml';
		var s = CommnUtil.ajax(url, { ids : cbox.join(",") }, "json");
		if (s == "success") {
			layer.msg('操作成功');
			grid.loadData();
		} else {
			layer.msg('操作失败');
		}
	});
}
function xianzai(url){
	window.open(rootPath + '/party/download.shtml?url='+url);
}
function viewFun(cbox) {
	pageii = layer.open({
		
		title : "查看",
		type : 2,
		area : [ "600px", "550px" ],
		content :rootPath + '/party/viewUI.shtml?id=' +cbox
	});
}
function recommend(){
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择推荐项！！");
		return;
	}
	var url = rootPath + '/party/recommendEntity.shtml';
	var s = CommnUtil.ajax(url, {
		ids : cbox.join(",")
	}, "json");
	if (s == "success") {
		layer.msg('推荐成功');
		grid.loadData();
	}
}
function unRecommend(){
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择取消项！！");
		return;
	}
	var url = rootPath + '/party/unRecommendEntity.shtml';
	var s = CommnUtil.ajax(url, {
		ids : cbox.join(",")
	}, "json");
	if (s == "success") {
		layer.msg('取消成功');
		grid.loadData();
	} 
}
function delFun() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！！");
		return;
	}
	layer.confirm('是否删除？删除后数据不可恢复', function(index) {
		var url = rootPath + '/party/deleteEntity.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('删除成功');
			grid.loadData();
		} else {
			layer.msg('活动已经进行,不可删除!');
		}
	});
}
function viewDetail(cbox){
	pageii = layer.open({
		title:"查看",
		type:2,
		area:["900px","530px"],
		content:rootPath + '/party/viewDetail.shtml?id=' +cbox
	});
}
</script>